package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 杨博超
 * @title GlobalExceptionHandler
 * @create 2025/1/11 10:08
 * @description
 */
@RestControllerAdvice //@ControllerAdvice + @ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    public Result error(LeaseException e) {
        e.printStackTrace();
        return Result.build(null, e.getCode(), e.getMessage());
    }

}
